//
//  YZMHintInputView.m
//  YZMicroStock
//
//  Created by Lv.Dongdong on 16/3/29.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMHintInputView.h"

@interface YZMHintInputView () <UITextFieldDelegate>

@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UIView *lineTopView;
@property (nonatomic, strong) UIView *lineBottomView;
@property (nonatomic, strong) UIView *rightWidget;
@property (nonatomic, strong) UIView *segmentLine;

@end

@implementation YZMHintInputView

- (id)init {
    if (self = [super init]) {
        self.backgroundColor = [YZMAppStyle colorForMain];
        [self createObjects];
    }
    return self;
}

- (void)createObjects {
    WS(ws)
    
    //提示标签
    self.inputLabel = [YZMAppStyle labelWithMediumWhite];
    [self addSubview:self.inputLabel];
    [self.inputLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.mas_left).with.offset(ControlSpacing15);
        make.centerY.equalTo(ws);
        make.height.mas_equalTo(ControlHeight18);
    }];
    [self.inputLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    [self.inputLabel setContentCompressionResistancePriority: UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    //提示标签 图片
    self.leftView = [[UIImageView alloc]init];
    [self addSubview:self.leftView];
    [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.mas_left).with.offset(ControlSpacing15);
        make.centerY.equalTo(ws);
        make.width.height.mas_equalTo(25);
    }];
    self.leftView.hidden=YES;
    
    
    //输入框
    self.textField = [YZMAppStyle inputTextField];
    self.textField.delegate = self;
    [ws addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.inputLabel.mas_right).with.offset(ControlSpacing20);
        make.right.equalTo(ws).with.offset(-ControlSpacing20);
        make.centerY.equalTo(ws);
        make.height.mas_equalTo(ControlHeight18);
    }];
    
    //上边框线
    self.lineTopView = [YZMAppStyle splitLine];
    self.lineTopView.hidden = YES;
    [self addSubview:self.lineTopView];
    [self.lineTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.top.equalTo(ws);
    }];
    
    //下边框线
    self.lineBottomView = [YZMAppStyle splitLine];
    self.lineBottomView.hidden = YES;
    [self addSubview:self.lineBottomView];
    [self.lineBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(ws);
    }];
    
    //右侧按钮
    self.rightWidget = [[UIView alloc] init];
    [self addSubview:self.rightWidget];
    
    //分割线
    self.segmentLine = [[UIView alloc] init];
    self.segmentLine.backgroundColor = [YZMAppStyle colorForIconColor];
    self.segmentLine.hidden = YES;
    [self addSubview:self.segmentLine];
    
}

- (void)appendRightWidget:(UIView *)content isShowSegmentLine:(BOOL)isSegmentLine {
    
    WS(ws)
    [self.rightWidget addSubview:content];
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(ws.rightWidget);
    }];
    
    if (isSegmentLine) {
        
        self.segmentLine.hidden = NO;
        
        [self.textField mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(ws.inputLabel.mas_right).with.offset(ControlSpacing20);
            make.centerY.equalTo(ws);
            make.height.mas_equalTo(ControlHeight18);
        }];
        
        [self.segmentLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(ws.textField.mas_right).with.offset(ControlSpacing15).priorityMedium();
            make.centerY.equalTo(ws);
            make.height.mas_equalTo(ControlHeight30);
            make.width.mas_equalTo(0.5);
        }];
        
        
        [self.rightWidget mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(ws.segmentLine.mas_right).with.offset(ControlSpacing15);
            make.right.equalTo(ws).with.offset(-ControlSpacing15);
            make.centerY.equalTo(ws);
        }];
    } else {
        
        [self.textField mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(ws.inputLabel.mas_right).with.offset(ControlSpacing20);
            make.centerY.equalTo(ws);
            make.height.mas_equalTo(ControlHeight18);
        }];
        
        [self.rightWidget mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(ws.textField.mas_right).with.offset(ControlSpacing15);
            make.right.equalTo(ws).with.offset(-ControlSpacing15);
            make.centerY.equalTo(ws);
        }];
    }
}

- (void)updateLineIndentationMethod:(UIView *)LineView enumeration:(LINE_INDENT_SCENE)type indentValue:(CGFloat)value {
    
    LineView.hidden = NO;
    
    WS(ws)
    switch (type) {
        case LINE_INDENT_SCENE_LEFT: {
            [LineView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(ws.mas_left).with.offset(value);
            }];
            break;
        }
        case LINE_INDENT_SCENE_RIGHT: {
            [LineView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(ws.mas_right).with.offset(-value);
            }];
            break;
        }
        case LINE_INDENT_SCENE_BILTERL: {
            [LineView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(ws.mas_left).with.offset(value);
                make.right.equalTo(ws.mas_right).with.offset(-value);
            }];
            break;
        }
        default: {
            break;
        }
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.textField resignFirstResponder];
    return YES;
}

@end
